﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CondominioWeb.Negocio;
using CondominioWeb.Dominio;

namespace CondominioWeb.Controllers
{
    public class AreasComunesController : Controller
    {
        public AdministracionService oAdministracionService  { get; set; }
        // GET: /AreasComunes/

        public ActionResult Index()
        {
            ICollection<Area_Comun> Modelo = oAdministracionService.ListarTodasAreasComunes();

            return View(Modelo);
        }


        //
        // GET: /AreasComunes/Create

        public ActionResult Create()
        {

            return View();
        } 

        //
        // POST: /AreasComunes/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                if (ModelState.IsValid)
                {

                    
                    Int32 Codigo_Area_Comun= Int32.Parse((String)collection["oTipo_Area_Comun"]);                        
                    Int32 Codigo_Zona=Int32.Parse((String)collection["oZona"]); 

                    Area_Comun OArea_Comun=new Area_Comun();                    
                    OArea_Comun.Codigo_Area_Comun= Int32.Parse((String)collection["Codigo_Area_Comun"]); 
                    OArea_Comun.Capacidad=Int32.Parse((String)collection["Capacidad"]);                    
                    OArea_Comun.Estado=(String)collection["Estado"];

                    oAdministracionService.CrearAreaComun(OArea_Comun.Codigo_Area_Comun,
                                                        Codigo_Area_Comun,Codigo_Zona, 
                                                        OArea_Comun.Capacidad, OArea_Comun.Estado);
                            
                }

                return RedirectToAction("Index");
            }
            catch
            {
                ModelState.AddModelError(string.Empty, "Error al crear el area comun.");
                return View();
            }
        }
        
        //
        // GET: /AreasComunes/Edit/5
 
        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /AreasComunes/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {

 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /AreasComunes/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /AreasComunes/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
